@extends('layouts.analyse')

@section('title', '商品统计')

@section('content')
    <div class="navigation">
        <a>后台管理</a>
        <span>></span>
        <a>商品管理</a>
        <span>></span>
        <a>商品列表</a>
    </div>

    <div class="content-div">
        <form method="post" id="listForm" autocomplete="off">
            {{form_verify_field()}}
            <input type="hidden" name="eventType" value="" id="eventType">
            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="listtable">
                <thead>
                <tr>
                    <th width="40">图片</th>
                    <th>商品名称</th>
                    <th>目录分类</th>
                    <th>价格</th>
                    <th>销量</th>
                    <th width="140">上架时间</th>
                </tr>
                </thead>
                <tbody>
                @foreach($items as $item)
                    <tr>
                        <td>
                            <a href="{{item_url($item['itemid'])}}" target="_blank">
                                <div class="bg-cover" style="background-image: url({{image_url($item['thumb'])}}); width: 40px; height: 40px;"></div>
                            </a>
                        </td>
                        <td><strong>{{$item['title']}}</strong></td>
                        <td>{{$catlognames[$item['catid']] or ''}}</td>
                        <td><p><strong style="color: #f40;">{{$item['price']}}</strong></p></td>
                        <td>{{$item['sold']}}</td>
                        <td>{{@date('Y-m-d H:i:s', $item['created_at'])}}</td>
                    </tr>
                @endforeach
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="20">
                        <div class="pagination float-right">{{$pagination}}</div>
                        <div class="btn-group-sm">
                            <label><input type="checkbox" data-action="checkall"> 全选</label>
                            <label><button type="button" class="btn btn-default btn-action" data-action="delete" disabled="disabled">删除</button></label>
                            <label><button type="button" class="btn btn-default btn-action" data-action="on_sale" disabled="disabled">上架</button></label>
                            <label><button type="button" class="btn btn-default btn-action" data-action="off_sale" disabled="disabled">下架</button></label>
                            <label><button type="button" class="btn btn-default btn-action" disabled="disabled">移动</button></label>
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
    <form method="post" id="J_Frmmove" action="{U:('c=item&a=move')}"><input type="hidden" name="items" id="J_items"></form>
    <script type="text/javascript">
        $(function () {
            $(document).on('click', function () {
                if ($(".checkmark:checked").length > 0) {
                    $(".btn-action").enable();
                } else {
                    $(".btn-action").disable();
                }
            });
            $(".btn-action").on('click', function () {
                var eventType = $(this).attr('data-action');
                var submitForm = function () {
                    $("#listForm").ajaxSubmit({
                        dataType:'json',
                        beforeSend:function () {
                            DSXUI.showSpinner();
                        },
                        success:function (response) {
                            setTimeout(function () {
                                DSXUI.hideSpinner();
                                if (response.errcode){
                                    DSXUI.error(response.errmsg);
                                }else {
                                    DSXUtil.reFresh();
                                }
                            }, 500);
                        }
                    });
                };
                $("#eventType").val(eventType);
                if (eventType === 'delete') {
                    DSXUI.showConfirm('删除商品', '确认要删除所选商品吗?', function () {
                        submitForm();
                    });
                }else {
                    submitForm();
                }
            });

            $(".btn-move").on('click', function () {
                var items = [];
                $(".checkmark:checked").each(function () {
                    items.push($(this).val());
                });
                $("#J_items").val(items.join(','));
                $("#J_Frmmove").submit();
            });
        });
    </script>
@stop
